package main

import (
	"github.com/gorilla/websocket"
	"log"
)

type Message struct {
	Email    string `json:"email"`
	Username string `json:"username"`
	Message  string `json:"message"`
}

func main() {
	// 连接到WebSocket服务
	dialer := websocket.Dialer{}
	conn, _, err := dialer.Dial("ws://localhost:8001/ws", nil)
	if err != nil {
		log.Fatal("Error connecting to WebSocket server:", err)
	}
	defer conn.Close()

	// 创建并发送消息
	msg := Message{
		Email:    "user@example.com",
		Username: "user2",
		Message:  "Hi there!",
	}

	if err := conn.WriteJSON(msg); err != nil {
		log.Fatal("Error sending message:", err)
	}

	// 等待响应或消息（可选）
	_, message, err := conn.ReadMessage()
	if err != nil {
		log.Fatal("Error reading message:", err)
	}
	log.Printf("Received: %s\n", message)
}
